package br.com.dataphonebr.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.annotation.SuppressLint;

public class AlarmVO {
	
	public final static String TODAY_LIST_SEPARATOR = "/";
	private Long id;
	private Integer requestCode;
	private Date time;
	private boolean read;
	private boolean sent;
	
	public AlarmVO() {
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Integer getRequestCode() {
		return requestCode;
	}
	public void setRequestCode(Integer requestCode) {
		this.requestCode = requestCode;
	}
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	
	public boolean isRead() {
		return read;
	}
	
	public void setRead(boolean read) {
		this.read = read;
	}
	
	public boolean isSent() {
		return sent;
	}
	
	public void setSent(boolean sent) {
		this.sent = sent;
	}
	
	public Calendar getAlarmFromCalendar(){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(time);
    	return calendar;
	}

//	public AlarmVO(Parcel in) {
//        this.id = in.readLong();
//        this.requestCode = in.readInt();
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTimeInMillis(in.readLong());
//        this.time = calendar.getTime();
//	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((requestCode == null) ? 0 : requestCode.hashCode());
		result = prime * result + ((time == null) ? 0 : time.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AlarmVO other = (AlarmVO) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (requestCode == null) {
			if (other.requestCode != null)
				return false;
		} else if (!requestCode.equals(other.requestCode))
			return false;
		if (time == null) {
			if (other.time != null)
				return false;
		} else if (!time.equals(other.time))
			return false;
		return true;
	}
	
	public boolean isValid(){
		if (this.stringAlarm() != null && !this.stringAlarm().isEmpty()){
			return true;
		}
		return false;
	}
	
	public String stringAlarm() {
		if (id != null && time != null){
			StringBuffer bufferAlarm = new StringBuffer();
			bufferAlarm.append(id);
			bufferAlarm.append(TODAY_LIST_SEPARATOR);
			bufferAlarm.append(getTimeToString());
			bufferAlarm.append(TODAY_LIST_SEPARATOR);
			bufferAlarm.append(requestCode);
			return bufferAlarm.toString();
		}
		return null;
//		if (id != null && time != null && requestCode != null){
//			StringBuffer bufferAlarm = new StringBuffer();
//			bufferAlarm.append(id);
//			bufferAlarm.append(TODAY_LIST_SEPARATOR);
//			String alarm1 = getHoraPadrao();
//			if (time != null) 
//				alarm1 = timeToString(time);
//			bufferAlarm.append(alarm1);
//			bufferAlarm.append(TODAY_LIST_SEPARATOR);
//			bufferAlarm.append(requestCode);
//			return bufferAlarm.toString();
//		}
//		return null;
	}
	
    @SuppressLint("SimpleDateFormat") 
    private String getTimeToString(){
    	Date newTime = time;
    	if (newTime == null)
    		newTime = new Date();
    	DateFormat formatter; 
    	formatter = new SimpleDateFormat("HH:mm");
    	String dateStr = formatter.format(time);
    	return dateStr;
    }

//    @Override
//	public int describeContents() {
//		// TODO Auto-generated method stub
//		return 0;
//	}
//	@Override
//	public void writeToParcel(Parcel dest, int flags) {
//		dest.writeLong(id);
//        dest.writeInt(requestCode);
//        dest.writeLong(getAlarmFromCalendar().getTimeInMillis());
//	}

//	public static final Parcelable.Creator<AlarmVO> CREATOR = new Parcelable.Creator<AlarmVO>() {
//	 
//   @Override
//   public AlarmVO createFromParcel(Parcel source) {
//       return new AlarmVO(source);
//   }
//
//   @Override
//   public AlarmVO[] newArray(int size) {
//       return new AlarmVO[size];
//   }
//};
}
